package com.ruoyi.gxs.service.impl;

import java.util.List;

import com.ruoyi.gxs.domain.GxsComprehensive;
import com.ruoyi.gxs.mapper.GxsComprehensiveMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.gxs.mapper.GxsSchoolrecordMapper;
import com.ruoyi.gxs.domain.GxsSchoolrecord;
import com.ruoyi.gxs.service.IGxsSchoolrecordService;

/**
 * 学习成绩Service业务层处理
 * 
 * @author 高晓松
 * @date 2023-12-27
 */
@Service
public class GxsSchoolrecordServiceImpl implements IGxsSchoolrecordService 
{
    @Autowired
    private GxsSchoolrecordMapper gxsSchoolrecordMapper;

    @Autowired
    private GxsComprehensiveMapper gxsComprehensiveMapper;

    /**
     * 查询学习成绩
     * 
     * @param gxsId 学习成绩主键
     * @return 学习成绩
     */
    @Override
    public GxsSchoolrecord selectGxsSchoolrecordByGxsId(Long gxsId)
    {
        return gxsSchoolrecordMapper.selectGxsSchoolrecordByGxsId(gxsId);
    }

    /**
     * 查询学习成绩列表
     * 
     * @param gxsSchoolrecord 学习成绩
     * @return 学习成绩
     */
    @Override
    public List<GxsSchoolrecord> selectGxsSchoolrecordList(GxsSchoolrecord gxsSchoolrecord)
    {
        return gxsSchoolrecordMapper.selectGxsSchoolrecordList(gxsSchoolrecord);
    }

    /**
     * 新增学习成绩
     * 
     * @param gxsSchoolrecord 学习成绩
     * @return 结果
     */
    @Override
    public int insertGxsSchoolrecord(GxsSchoolrecord gxsSchoolrecord)
    {
        GxsComprehensive comprehensive = gxsComprehensiveMapper.selectGxsComprehensiveByUserName(gxsSchoolrecord.getUserName());
        comprehensive.setGxsSchoolrecord((long)gxsSchoolrecord.getGxsSchoolrecord());
        comprehensive.setGxsFail(gxsSchoolrecord.getGxsFail());

        Long gxsThought = comprehensive.getGxsThought();
        Long gxsSportsscore = comprehensive.getGxsSportsscore();
        //Long gxsAppraisalScore = comprehensive.getGxsAppraisalScore();

        comprehensive.setGxsAppraisalScore(gxsThought + gxsSportsscore + (long)gxsSchoolrecord.getGxsSchoolrecord());

        gxsComprehensiveMapper.updateGxsComprehensive(comprehensive);

        return gxsSchoolrecordMapper.insertGxsSchoolrecord(gxsSchoolrecord);
    }

    /**
     * 修改学习成绩
     * 
     * @param gxsSchoolrecord 学习成绩
     * @return 结果
     */
    @Override
    public int updateGxsSchoolrecord(GxsSchoolrecord gxsSchoolrecord)
    {
        return gxsSchoolrecordMapper.updateGxsSchoolrecord(gxsSchoolrecord);
    }

    /**
     * 批量删除学习成绩
     * 
     * @param gxsIds 需要删除的学习成绩主键
     * @return 结果
     */
    @Override
    public int deleteGxsSchoolrecordByGxsIds(Long[] gxsIds)
    {
        return gxsSchoolrecordMapper.deleteGxsSchoolrecordByGxsIds(gxsIds);
    }

    /**
     * 删除学习成绩信息
     * 
     * @param gxsId 学习成绩主键
     * @return 结果
     */
    @Override
    public int deleteGxsSchoolrecordByGxsId(Long gxsId)
    {
        return gxsSchoolrecordMapper.deleteGxsSchoolrecordByGxsId(gxsId);
    }
}
